<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>欢迎页</title>
    <link rel="stylesheet" href="../../static/frame/layui/css/layui.css">
    <link rel="stylesheet" href="../../static/frame/static/css/style.css">
    <link rel="icon" href="../../static/frame/static/image/code.png">
</head>
<body class="body">

<div class="layui-row layui-col-space10 my-index-main">
    <div class="layui-col-xs4 layui-col-sm2 layui-col-md2">
        <div class="my-nav-btn layui-clear">
            <div class="layui-col-md5">
                <button class="layui-btn layui-btn-big layui-btn-danger layui-icon">&#xe756;</button>
            </div>
            <div class="layui-col-md7 tc">
                <p class="my-nav-text" id="appnum">loading</p>
                <p class="my-nav-text layui-elip">应用数量</p>
            </div>
        </div>
    </div>
    <div class="layui-col-xs4 layui-col-sm2 layui-col-md2">
        <div class="my-nav-btn layui-clear">
            <div class="layui-col-md5">
                <button class="layui-btn layui-btn-big layui-btn-warm layui-icon">&#xe735;</button>
            </div>
            <div class="layui-col-md7 tc">
                <p class="my-nav-text" id="sysver">loading</p>
                <p class="my-nav-text layui-elip">系统版本</p>
            </div>
        </div>
    </div>
    <div class="layui-col-xs4 layui-col-sm2 layui-col-md2">
        <div class="my-nav-btn layui-clear">
            <div class="layui-col-md5">
                <button class="layui-btn layui-btn-big layui-icon">&#xe715;</button>
            </div>
            <div class="layui-col-md7 tc">
                <p class="my-nav-text" id="czkeynum">loading</p>
                <p class="my-nav-text layui-elip">充值卡密</p>
            </div>
        </div>
    </div>
    <div class="layui-col-xs4 layui-col-sm2 layui-col-md2">
        <div class="my-nav-btn layui-clear">
            <div class="layui-col-md5">
                <button class="layui-btn layui-btn-big layui-btn-normal layui-icon">&#xe705;</button>
            </div>
            <div class="layui-col-md7 tc">
                <p class="my-nav-text" id="tckeynum">loading</p>
                <p class="my-nav-text layui-elip">套餐卡密</p>
            </div>
        </div>
    </div>
    <div class="layui-col-xs4 layui-col-sm2 layui-col-md2">
        <div class="my-nav-btn layui-clear">
            <div class="layui-col-md5">
                <button class="layui-btn layui-btn-big layui-bg-cyan layui-icon">&#xe6b2;</button>
            </div>
            <div class="layui-col-md7 tc">
                <p class="my-nav-text" id="agentnum">loading</p>
                <p class="my-nav-text layui-elip">代理数量</p>
            </div>
        </div>
    </div>
    <div class="layui-col-xs4 layui-col-sm2 layui-col-md2">
        <div class="my-nav-btn layui-clear">
            <div class="layui-col-md5">
                <button class="layui-btn layui-btn-big layui-bg-black layui-icon">&#xe698;</button>
            </div>
            <div class="layui-col-md7 tc">
                <p class="my-nav-text" id="tradenum">loading</p>
                <p class="my-nav-text layui-elip">订单数量</p>
            </div>
        </div>
    </div>

    <div class="layui-col-xs12">
        <div class="layui-collapse">
            <div class="layui-colla-item">
                <h2 class="layui-colla-title">来自温泉授权服务器的系统公告</h2>
                <div class="flow-default layui-colla-content layui-show" id="notice">

                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-xs12">
        <div class="layui-collapse">
            <div class="layui-colla-item">
                <h2 class="layui-colla-title">检查系统更新</h2>
                <div class="flow-default layui-colla-content layui-show" id="update">
                    <button class="layui-btn layui-btn-radius layui-btn-normal" style="width: 100%" onclick="update()">
                        立即检查更新
                    </button>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-xs12">
        <div class="layui-collapse">
            <div class="layui-colla-item">
                <h2 class="layui-colla-title">系统更新日志</h2>
                <div class="flow-default layui-colla-content layui-show" id="uplog">

                </div>
            </div>
        </div>
    </div>
</div>
<script src="../../static/jquery-3.3.1.js"></script>
<script type="text/javascript" src="../../static/frame/layui/layui.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>
<script type="text/javascript" src="../../static/frame/echarts/echarts.min.js"></script>
<script type="text/javascript">
    layui.use(['flow', 'element', 'layer', 'vip_tab'], function () {
        // 打开选项卡
        var flow = layui.flow, vipTab = layui.vip_tab;
        $('.my-nav-btn').on('click', function () {
            if ($(this).attr('data-href')) {
                //vipTab.add('','标题','路径');
                vipTab.add($(this), '<i class="layui-icon">' + $(this).find("button").html() + '</i>' + $(this).find('p:last-child').html(), $(this).attr('data-href'));
            }
        });


        $.ajax({
            url: '../ajax.php?mod=getsysinfo',
            type: 'POST',
            dataType: 'json',
            data: '',
            success: function (data) {
                $('#appnum').html(data.appnum);
                $('#sysver').html(data.sysver);
                $('#czkeynum').html(data.czkeynum);
                $('#tckeynum').html(data.tckeynum);
                $('#agentnum').html(data.agentnum);
                $('#tradenum').html(data.tradenum);
            },
            error: function (data) {
                $('#appnum').html('error');
                $('#sysver').html('error');
                $('#czkeynum').html('error');
                $('#tckeynum').html('error');
                $('#agentnum').html('error');
                $('#tradenum').html('error');
            }
        });

        flow.load({
            elem: '#notice'
            , scrollElem: '#notice'
            , done: function (page, next) {
                var lis = [];
                $.ajax({
                    url: '../ajax.php?mod=getnotice',
                    type: 'POST',
                    dataType: 'html',
                    data: '',
                    success: function (data) {
                        $('#notice').html(data);
                        next();
                    },
                    error: function (data) {
                        $('#notice').html('嗷呜o(╥﹏╥)o 获取公告请求失败啦');
                        next();
                    }
                });
                //假设总页数为 6
            }
        });

        flow.load({
            elem: '#uplog'
            , scrollElem: '#uplog'
            , done: function (page, next) {
                var lis = [];
                $.ajax({
                    url: '../ajax.php?mod=getuplog',
                    type: 'POST',
                    dataType: 'html',
                    data: '',
                    success: function (data) {
                        $('#uplog').html('<div style="width: 100%;height: 800px;">\n' +
                            '      <textarea class="layui-textarea" style="width: 100%;height: 800px;">' + data + '</textarea>\n' +
                            '    </div>');
                        next();
                    },
                    error: function (data) {
                        $('#uplog').html('嗷呜o(╥﹏╥)o 获取系统更新日志失败啦');
                        next();
                    }
                });
                //假设总页数为 6
            }
        });


    });

    function update() {
        var loading = layer.load();
        $.ajax({
            url: '../ajax.php?mod=checkupdate',
            type: 'GET',
            dataType: 'html',
            data: '',
            success: function (data) {
                layer.close(loading);
                if (data === '1') {
                    layer.confirm('发现更新，请问是否立即进行更新？', {
                        btn: ['确定', '取消'] //按钮
                    }, function () {
                        loading = layer.msg('正在下载更新包', {
                            icon: 16
                            , shade: 0.01
                            , time: 0
                        });
                        $.ajax({
                            url: '../ajax.php?mod=downloadupdatepacks',
                            type: 'GET',
                            dataType: 'json',
                            data: '',
                            success: function (data) {
                                layer.close(loading);
                                if (data.code === '1') {

                                    loading = layer.msg('正在解压更新包', {
                                        icon: 16
                                        , shade: 0.01
                                        , time: 0
                                    });
                                    $.ajax({
                                        url: '../ajax.php?mod=unzippacks',
                                        type: 'GET',
                                        dataType: 'json',
                                        data: '',
                                        success: function (data) {
                                            layer.close(loading);
                                            if (data.code === '1') {
                                                loading = layer.msg('正在安装更新包', {
                                                    icon: 16
                                                    , shade: 0.01
                                                    , time: 0
                                                });
                                                $.ajax({
                                                    url: data.updateurl,
                                                    type: 'GET',
                                                    dataType: 'html',
                                                    data: '',
                                                    success: function (data) {
                                                        layer.close(loading);
                                                        layer.alert(data);
                                                    },
                                                    error: function (data) {
                                                        layer.close(loading);
                                                        layer.msg('请求失败' + data.code);
                                                    }
                                                })
                                            } else {
                                                layer.msg(data.msg);
                                            }
                                        },
                                        error: function (data) {
                                            layer.close(loading);
                                            layer.msg('请求失败' + data.code);
                                        }
                                    })
                                } else {
                                    layer.close(loading);
                                    layer.msg(data.msg);
                                }


                            },
                            error: function (data) {
                                layer.close(loading);
                                layer.msg('请求失败' + data.code);
                            }
                        })
                    });
                } else if (data === '-1') {
                    layer.alert('您当前已是最新版');
                } else {
                    layer.alert(data);
                }
            },
            error: function (data) {
                layer.close(loading);
                layer.msg('请求失败' + data);
            }
        })

    }

</script>
</body>
</html>